package com.lty.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lty.mapper.TemplateMapper;
import com.lty.model.entity.TemplateInfo;
import com.lty.model.enums.StatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lty
 */
@Slf4j
@Service
public class TemplateService extends ServiceImpl<TemplateMapper, TemplateInfo> {

    @Resource
    private TemplateMapper templateMapper;


    /**
     * 查询列表
     * @return
     */
    public List<TemplateInfo> getList() {
        QueryWrapper<TemplateInfo> qw = new QueryWrapper<>();
        qw.eq("status", StatusEnum.ENABLE.getValue());
        qw.orderByAsc("sortable");
        return templateMapper.selectList(qw);
    }


    public Wrapper<TemplateInfo> buildQueryWrapper(TemplateInfo templateInfo) {
        QueryWrapper<TemplateInfo> qw = new QueryWrapper<>();
        qw.eq(StringUtils.isNotBlank(templateInfo.getCode()), "code", templateInfo.getCode());
        qw.orderByAsc("sortable");
        return qw;
    }
}